package com.yyt.module_main.vm;

import android.content.Intent;
import android.databinding.ObservableField;
import android.os.Bundle;
import android.view.View;

import com.yyt.libsrc.bean.BaseCallbackBean;
import com.yyt.libsrc.conf.Consts;
import com.yyt.libsrc.helper.LocalHelper;
import com.yyt.libsrc.net.JavaParamsBuilder;
import com.yyt.libsrc.net.NetUtil;
import com.yyt.libsrc.net.SimpleNetCallBack;
import com.yyt.libsrc.net.SuccessCallback;
import com.yyt.libsrc.router.RouteTable;
import com.yyt.libsrc.router.RouterHelper;

import top.lixb.libcommon.binding.BindingViewModel;
import top.lixb.libcommon.dialog.IOSAlertDialog;

public class SysSettingVM extends BindingViewModel {
    public ObservableField<String> iconUrl = new ObservableField<>();
    public ObservableField<String> uname = new ObservableField<>();
    public ObservableField<String> mobile = new ObservableField<>();
    public ObservableField<String> IDCardNo = new ObservableField<>();
    public ObservableField<String> servicePhone = new ObservableField<>();


    /**
     * 修改密码
     * @param view
     */
    public void changePwd(View view) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("isModify",true);
        bundle.putString("mobile",mobile.get());
        RouterHelper.getInstance().startAct(RouteTable.main_forget_pwd,bundle);
    }

    public void aboutUs(View view) {
        RouterHelper.getInstance().startAct(RouteTable.main_about);
    }


    public void logout(View view) {
        if (null!=mActivity && !mActivity.isFinishing()) {
            new IOSAlertDialog(mActivity).builder().setMsg("是否要退出登录").setPositiveButton("确定", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    NetUtil.sellerPost(new JavaParamsBuilder()
                            .addCmd(Consts.CMD.logOut)
                            .build(), new SuccessCallback<BaseCallbackBean>() {
                        @Override
                        public void onSuccess(BaseCallbackBean baseCallbackBean) {

                        }
                    });
                    LocalHelper.saveTicket("");
                    RouterHelper.getInstance().startAct(RouteTable.main_login, Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
                }
            }).setNegativeButton("取消",null).show();
        }
    }
}
